
// Open MoneySpinner Suite v1
// An open source business management software system written in Java and MySQL
// Recommended IDE is NetBeans IDE 7.0.1
// Support Web Site: http://www.milliscript.com
//
// Copyright (C) 2014, Abiodun Aremu, Ibadan/NIGERIA.
// Open MoneySpinner Suite is distributed under the terms of the Apache License version 2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package openmoneyspinnersuite;

/**
 *
 * @author Abiodun Aremu
 */
import javax.swing.*;

final class ProfileConstant extends javax.swing.JInternalFrame {

    Object[][] tableObject=new Object[1][2];
    Systems systems=new Systems();
    java.sql.PreparedStatement statement;
    Thread processThread=new Thread();
    Thread titleThread=new Thread();
    String[] attributeList=new String[]{};
    int updateType=0;
    String profileName="",addInUse,delInUse;
    
    /** Creates new form ViewCredit */
    ProfileConstant() {
        initComponents();
        tableObject[0][0]="1";
        tableObject[0][1]="";
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Profile Constant"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true
            };

            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class
            };
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            reset();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jRefreshButton = new javax.swing.JButton();
        jCancelButton = new javax.swing.JButton();
        jUpdateButton = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jAddButton = new javax.swing.JButton();
        jDeleteButton = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(openmoneyspinnersuite.OpenMS_Finance_App.class).getContext().getResourceMap(ProfileConstant.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setToolTipText(resourceMap.getString("Form.toolTipText")); // NOI18N
        setFrameIcon(resourceMap.getIcon("Form.frameIcon")); // NOI18N
        setName("Form"); // NOI18N
        setVisible(true);

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "S/N", "Constant"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
        jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N

        jRefreshButton.setFont(resourceMap.getFont("jRefreshButton.font")); // NOI18N
        jRefreshButton.setIcon(resourceMap.getIcon("jRefreshButton.icon")); // NOI18N
        jRefreshButton.setText(resourceMap.getString("jRefreshButton.text")); // NOI18N
        jRefreshButton.setName("jRefreshButton"); // NOI18N
        jRefreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRefreshButtonActionPerformed(evt);
            }
        });

        jCancelButton.setFont(resourceMap.getFont("jCancelButton.font")); // NOI18N
        jCancelButton.setIcon(resourceMap.getIcon("jCancelButton.icon")); // NOI18N
        jCancelButton.setText(resourceMap.getString("jCancelButton.text")); // NOI18N
        jCancelButton.setName("jCancelButton"); // NOI18N
        jCancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCancelButtonActionPerformed(evt);
            }
        });

        jUpdateButton.setIcon(resourceMap.getIcon("jUpdateButton.icon")); // NOI18N
        jUpdateButton.setText(resourceMap.getString("jUpdateButton.text")); // NOI18N
        jUpdateButton.setName("jUpdateButton"); // NOI18N
        jUpdateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUpdateButtonActionPerformed(evt);
            }
        });

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setName("jComboBox1"); // NOI18N
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-- Select --", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.setName("jComboBox2"); // NOI18N
        jComboBox2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox2ActionPerformed(evt);
            }
        });

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jAddButton.setIcon(resourceMap.getIcon("jAddButton.icon")); // NOI18N
        jAddButton.setText(resourceMap.getString("jAddButton.text")); // NOI18N
        jAddButton.setName("jAddButton"); // NOI18N
        jAddButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jAddButtonActionPerformed(evt);
            }
        });

        jDeleteButton.setIcon(resourceMap.getIcon("jDeleteButton.icon")); // NOI18N
        jDeleteButton.setText(resourceMap.getString("jDeleteButton.text")); // NOI18N
        jDeleteButton.setName("jDeleteButton"); // NOI18N
        jDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jDeleteButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addGap(35, 35, 35)
                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 376, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(12, Short.MAX_VALUE))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jAddButton, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jDeleteButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRefreshButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jUpdateButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jCancelButton))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jUpdateButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jAddButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jDeleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jRefreshButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRefreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRefreshButtonActionPerformed
  
            reset();

    }//GEN-LAST:event_jRefreshButtonActionPerformed

    private void jCancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelButtonActionPerformed
        
        if(processThread.isAlive())
        {
            try{
                processThread.stop();
                titleThread.stop();
                System.out.println("Threads successfully stopped.");
            }catch(Exception e){System.out.println("Thread stopping error: "+e);}
            this.setTitle("::. Profile Constant");
            enableControls();
        }
        else
        dispose();
    }//GEN-LAST:event_jCancelButtonActionPerformed

private void jUpdateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUpdateButtonActionPerformed

    if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
    {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select A Profile ","ERROR !",JOptionPane.ERROR_MESSAGE);
        return;
    }
    if(jComboBox2.getSelectedItem().toString().equalsIgnoreCase("-- Select --"))
    {
        JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Please Select An Attribute ","ERROR !",JOptionPane.ERROR_MESSAGE);
        return;
    }
    submitData();
    reset();
}//GEN-LAST:event_jUpdateButtonActionPerformed
void submitData()
{        
    int x=0,y=tableObject.length;
    String profileCode=systems.getValue(OpenMSApp.Database_A, "Select cReferenceTableCode from referenceTable where vName='"+jComboBox1.getSelectedItem().toString().toString()+"'", 1);
    //Connect.createMSSQLConnection();
    Connect.changeDB(OpenMSApp.Database_A);
    statement=Connect.createStatement(Connect.procInit+" prnDelProfileConstant"+Connect.procInitStart+"?,?"+Connect.procInitEnd);
    try
    {
        statement.setString(1,profileCode);
        statement.setString(2,jComboBox2.getSelectedItem().toString().toString());
    }
    catch(Exception e)
    {
        System.out.println("ProfileConstant.submitData() gave error ! "+e);
    }
    Connect.executeUpdateStatement(statement);
    for(;x<y;x++)
    {
        statement=Connect.createStatement(Connect.procInit+" prnInsProfileConstant"+Connect.procInitStart+"?,?,?"+Connect.procInitEnd);
        try
        {
            statement.setString(1,profileCode);
            statement.setString(2,jComboBox2.getSelectedItem().toString().toString());
            statement.setString(3,jTable1.getValueAt(x, 1).toString());
        }
        catch(Exception e)
        {
            System.out.println("EditMerchantQuery.submitData() gave error ! "+e);
        }
        Connect.executeUpdateStatement(statement);
    }
    Connect.alert="Y";
    Connect.closeConnection();
}
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        
        /* Execute thread */
        processThread=new Thread(new Runnable() {
            public void run() {
                disableControls();
                profileCodeSelected();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewProfileThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start();
}//GEN-LAST:event_jComboBox1ActionPerformed

private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
        String attributeConstant[]=systems.getColumn(OpenMSApp.Database_A, "Select vConstant from profileConstant where cProfileCode='"+systems.getValue(OpenMSApp.Database_A, "Select cReferenceTableCode from referenceTable where vName='"+jComboBox1.getSelectedItem().toString().toString()+"'",1)+"' and vAttribute='"+jComboBox2.getSelectedItem().toString()+"'", 1);
        if(attributeConstant.length>0)
        tableObject=new Object[attributeConstant.length][2];
        for(int x=0;x<attributeConstant.length;x++)
        {
            tableObject[x][0]=x+1;
            tableObject[x][1]=attributeConstant[x];
        }
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Profile Constant"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);
}//GEN-LAST:event_jComboBox2ActionPerformed

    public void addRow()
    {
        addInUse="Y";
        //System.out.println("Add in use:"+addInUse);
        int x=tableObject.length;
        int y=x+1;
        Object[][] holdObject=new Object[y][2];

        for(int z=0;z<x;z++)
        {
            if(jTable1.getValueAt(z,1)==null)
            {
                JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"NULL VALUE FOUND ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
                return;
            }
        }

        for(int z=0;z<x;z++)
        {
            if(jTable1.getValueAt(z,1)!=null)
            {
                holdObject[z][0]=z+1;
                holdObject[z][1]=jTable1.getValueAt(z,1).toString();
                holdObject[y-1][0]=y;
            }

        }

        //System.out.println(holdObject[0][0]+""+holdObject[0][1]+""+holdObject[0][2]+""+holdObject[0][3]+""+holdObject[0][4]+""+holdObject[0][5]);

        tableObject=holdObject;

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Profile Constant"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);

        addInUse="N";
    }                                   
    void deleteRow()
    {
        delInUse="Y";
        System.out.println("delete In Use"+delInUse);
        int x=tableObject.length;
        int y=x-1;
        Object[][] holdObject=new Object[y][2];

        if(x==1)
        {
            JOptionPane.showMessageDialog(JOptionPane.getRootFrame(),"Can Not Delete Row \n   Invalid Operation ! ","ERROR !",JOptionPane.ERROR_MESSAGE);
            return;
        }

        for(int z=0;z<x-1;z++)
        {
            if(jTable1.getValueAt(z,1)!=null)
            {
                holdObject[z][0]=z+1;
                holdObject[z][1]=jTable1.getValueAt(z,1).toString();
                holdObject[y-1][0]=y;
            }
        }
        tableObject=holdObject;

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Profile Constant"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false,true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });

        jTable1.getColumnModel().getColumn(0).setMinWidth(40);
        jTable1.getColumnModel().getColumn(0).setPreferredWidth(40);
        jTable1.getColumnModel().getColumn(0).setMaxWidth(40);
        jTable1.getColumnModel().getColumn(1).setPreferredWidth(10);

        delInUse="N";
    }
private void jAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddButtonActionPerformed
addRow();
}//GEN-LAST:event_jAddButtonActionPerformed

private void jDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jDeleteButtonActionPerformed
deleteRow();
}//GEN-LAST:event_jDeleteButtonActionPerformed
    private void disableControls()
    {
        jUpdateButton.setEnabled(false);
        jRefreshButton.setEnabled(false);
        jComboBox1.setEnabled(false);
    }                                             
    private void enableControls()
    {
        jUpdateButton.setEnabled(true);
        jRefreshButton.setEnabled(true);
        jComboBox1.setEnabled(true);
        this.setTitle("::. Profile Constant");
    }
                   
    private void setProcessingTitle(Thread thread)
    {
        try{
            this.setTitle("::. Profile Constant - Processing Request");
            thread.sleep(500);
            this.setTitle("::. Profile Constant - Processing Request.");
            thread.sleep(500);
            this.setTitle("::. Profile Constant - Processing Request..");
            thread.sleep(500);
            this.setTitle("::. Profile Constant - Processing Request...");
            thread.sleep(500);
        }catch(Exception e){System.out.println("Title thread"+e);}
    }
    void print()
    {
        try
        {
            jTable1.print();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }    
    private void profileCodeSelected()
    {        
        String orderCode=jComboBox1.getSelectedItem().toString();
        if(orderCode.equals("-- Select --"))
        {
            reset();
            resetProfileAttribute();
        }
        else
        {
            resetProfileAttribute();
            resetTable();
            setTitle("::. Profile Constant");
        }
    }
    void reset()
    {
        resetProfileCode();
        resetProfileAttribute();
        resetTable();
    }
    void resetCombo()
    {
        resetProfileCode();
        resetProfileAttribute();
        resetTable();
    }
    void resetTable()
    {
        tableObject=new Object[1][2];
        tableObject[0][0]="1";
        tableObject[0][1]="";
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            tableObject,
            new String [] {
                "S/N", "Profile Constant"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, true
            };

            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class
            };
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        /* Execute thread
        processThread=new Thread(new Runnable() {
            public void run() {
            disableControls();
            refreshTable();
            }
        });
        titleThread=new Thread(new Runnable() {
            public void run() {
                while(processThread.isAlive())setProcessingTitle(titleThread);
                enableControls();
                System.out.println("viewItemThread stopped runing.");
            }
        });
        processThread.start();
        titleThread.start(); */
    }
    void resetProfileCode()
    {
        String[] orderCode=systems.getTableDataArray(OpenMSApp.Database_A,"vwProfile",2);
        orderCode[0]="-- Select --";
        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(orderCode));
        setTitle("::. Profile Constant");
    }
    void resetProfileAttribute()
    {
        String profileCode=systems.getValue(OpenMSApp.Database_A, "select cReferenceTableCode from referenceTable where vName='"+jComboBox1.getSelectedItem().toString()+"'", 1);
        String[] orderCode=systems.getTableDataArray(OpenMSApp.Database_A," Profile where cprofileCode='"+profileCode+"'",2);
        orderCode[0]="-- Select --";
        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(orderCode));
        setTitle("::. Profile Constant");
    }
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAddButton;
    private javax.swing.JButton jCancelButton;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JButton jDeleteButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton jRefreshButton;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JButton jUpdateButton;
    // End of variables declaration//GEN-END:variables

}
